<?php
namespace app\models;
use common\component\tool\Tool;
use app\models\Basic;

use Yii;

class ContentAttrRelationships extends Basic
{
    
    public static function tableName()
    {
        return '{{%content_attr_relationships}}';
    }

    public function rules()
    {
        return [
            ['app_id', 'required', 'message' => 'app_id不能为空', 'on' => 'add'],
            ['app_id', 'integer', 'message' => 'app_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'app_id最小存储0', 
                        'max'=>65535, 'tooBig' => 'app_id最大存储65535'],
            ['content_id', 'required', 'message' => 'content_id不能为空'],
            ['content_id', 'integer', 'message' => 'content_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'content_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'content_id最大存储18446744073709551615'],
            ['attr_id', 'required', 'message' => 'attr_id不能为空'],
            ['attr_id', 'integer', 'message' => 'attr_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'attr_id最小存储0', 
                        'max'=>18446744073709551615, 'tooBig' => 'attr_id最大存储18446744073709551615'],
            ['attr_value', 'default', 'value' => ''],
            ['attr_value', 'string', 'message' => 'attr_value必须是字符串'],
        ];
    }


    /*添加*/
    public function addRelationships($data)
    {
        // P($data);
        $data['ContentAttrRelationships'] = $data;
        if($this->load($data) and $this->validate()){
            // P($this);
            if($this->save(false)){
                return true;
            }
        }
        return false;
    }


    /*关联查询 字段名*/
    public function getAttrName()
    {
        $name = $this->hasOne(ContentCategoryAttr::className(), ['attr_id' => 'attr_id'])->select(['{{%content_category_attr}}.attr_id', 'attr_name', 'attr_enname', 'attr_type', 'attr_value', 'limit', 'default_val']);
        return $name;
    }

    
}